package com.my.control.validate
{
	import com.my.commons.constants.ConstVars;
	import com.my.view.popup.RegisterView;
	
	import mx.core.UIComponent;
	
	public class RegisterViewValidate extends AbstractValidate implements IValidate
	{
		
		public function RegisterViewValidate(value:UIComponent)
		{
			super(value);
		}
		
		public override function validate():Boolean{
			
			var bool1:Boolean = usernameValidate();
			var bool2:Boolean  = passwordValidate();
			var bool3 :Boolean = passwordsValidate();
			var bool4 :Boolean = emailValidate();
			var bool5 :Boolean = checkValidate();
			var bool6 : Boolean = questionValidate();
			
			return bool1 && bool2 && bool3 && bool4 && bool5 && bool6;
		}
		
		private function usernameValidate():Boolean{
			if(getView().username.text.match(ConstVars.NAME_REGEX)){
				getView().usernameTip.text = "";
				return true;
			}else{
				getView().usernameTip.text = ConstVars.NAME_TIP;
				return false;
			}
		}
		private function passwordValidate():Boolean{
			if(getView().password.text.match(ConstVars.PASS_REGEX)){
				getView().passwordTip.text = "";
				return true;
			}else{
				getView().passwordTip.text = ConstVars.PASS_TIP;
				return false;
			}
		}
		private function passwordsValidate():Boolean{
			if(getView().passwords.text.match(ConstVars.PASS_REGEX) && getView().password.text == getView().passwords.text){
				getView().passwordsTip.text = "";
				return true;
			}else{
				getView().passwordsTip.text = "2次密码不相同";
				return false;
			}
		}
		private function emailValidate():Boolean{
			if(getView().email.text.match(ConstVars.EMAIL_REGEX)){
				getView().emailTip.text = "";
				return true;
			}else{
				getView().emailTip.text = ConstVars.EMAIL_TIP;
				return false;
			}
		}
		private function questionValidate():Boolean{
			if(getView().question.text != null && getView().question.text != ""){
				getView().questionTip.text = "";
				return true;
			}else{
				getView().questionTip.text = "请填写,用于找回密码";
				return false;
			}
		}
		private function checkValidate():Boolean{
			if(getView().check.text.match(ConstVars.CODE_REGEX)){
				getView().checkTip.text = "";
				return true;
			}else{
				getView().checkTip.text = ConstVars.CODE_TIP;
				return false;
			}
		}
		
		
		
		
		public function getView():RegisterView{
			return RegisterView(view);
		}
	}
}